import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}


object fav_name {
  def main(args: Array[String]): Unit = {
    val sparkconf = new SparkConf()
      .setMaster("local[*]")
    val sparksession = SparkSession
      .builder()
      .config(sparkconf)
      .enableHiveSupport()
      .appName("fav_count")
      .getOrCreate()

    var df = sparksession.sql(
      """
        |SELECT
        |    fav_count,
        |     product_id,
        |     title
        |FROM
        |    db_minsu.tb_minsu
        |ORDER BY
        |    fav_count DESC
        |limit 100;
        |""".stripMargin
    )
    val rat_view = df.createTempView("rat_view")
    val fav_name = sparksession.sql("select * from rat_view ")
    //dws_cardio_age.show()
    //-将结果进行存储，存储到 hive 数据库中

    fav_name.write.mode(SaveMode.Overwrite).saveAsTable("db_minsu.fav_name")



    sparksession.stop()
    sparksession.close()
  }
}
